package com.ssmk.module.shoppingcar.window;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.widget.AbsListView;
import android.widget.PopupWindow;

import com.ssmk.R;
import com.ssmk.utlis.BinderHelper;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 取消订单
 * Created by Rex on 2017/7/11.
 */

public class CancelOrderWindow extends PopupWindow {

    private View mContainer;

    private Unbinder mUnbinder;

    private OnCancelListener onCancelListener;

    public static CancelOrderWindow initPopupWindow(Context context) {
        View contentView = View.inflate(context, R.layout.order_cancel_popup, null);
        return new CancelOrderWindow(contentView);
    }

    private CancelOrderWindow(View contentView) {
        super(contentView, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT, false);
        mUnbinder = ButterKnife.bind(this, contentView);
        mContainer = contentView;
        initViews();
        defaultSet();
    }


    protected void defaultSet() {
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setFocusable(true);
        setOutsideTouchable(true);
        showAtLocation(mContainer, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    }

    public void setOnCancelListener(OnCancelListener onCancelListener) {
        this.onCancelListener = onCancelListener;
    }

    private void initViews() {

    }

    @OnClick(R.id.Cancel)
    public void onCancelClick() {
        dismiss();
    }

    @OnClick(R.id.NoPay)
    public void onNoPayClick() {
        if (null != onCancelListener)
            onCancelListener.onCancelClick("我不想买了");
        dismiss();
    }

    @OnClick(R.id.InfoError)
    public void onInfoErrorClick() {
        if (null != onCancelListener)
            onCancelListener.onCancelClick("信息填写错误，重新拍");
        dismiss();
    }

    @OnClick(R.id.OtherReason)
    public void onOtherReasonClick() {
        if (null != onCancelListener)
            onCancelListener.onCancelClick("其他原因");
        dismiss();
    }


    @Override
    public void dismiss() {
        super.dismiss();
        setContentView(null);
        BinderHelper.unbinder(mUnbinder);
    }

    public interface OnCancelListener {
        void onCancelClick(String flag);
    }


}
